<?php
/*
 * Author: Quan Van Sinh
 * Email: sinhvnb@vietnambiz.com
 */

checkLoginHeader();
checkPermission();
$article = new article();
$article->articleAction();
$category = $article->get_cat_tree(0);

?>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/header.php'; ?>


<script type="text/javascript" src="/admin/themes/default/js/article.js"></script>
<div id="wrapper">
    <div id="content" style="width: 98%;">
<?php
    

if ($_REQUEST['articleActionType'] == 'viewAddArticle' OR $_REQUEST['articleActionType'] == 'editArticle') {
    ?>
            <script type="text/javascript" src="/admin/themes/default/js/nicEdit.js"></script>
            <div id="articleAction">
                <div id="box">
                    <div id="rightnow">
                        <h3 class="reallynow">
                            <span>Article Actions</span>
                            <a href="/<?php echo $config ['admin_section']; ?>/article">List article</a><br />
                        </h3>
                    </div>
    <?php
    if ($_REQUEST['articleActionType'] == 'viewAddArticle') {
        ?>
                        <div id="formAddArticle">
                            <form method="post" action="/<?php echo $config ['admin_section']; ?>/article" id="form" name="formAddArticle" enctype="multipart/form-data" style="padding-top: 10px">
                                <fieldset id="fsAddArticle">
                                    <legend>Add article</legend>
                                    <table border="0" width="99%">
                                        <tbody>
                                            <tr>
                                                <td valign="top">
                                                    Title : <span id="titleAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please insert article title.</span><br>
                                                    <textarea id="title" name="title" rows="1" cols="10" style="clear:both;width: 504px; height:16px; background:none;"></textarea>
                                                    <input type="hidden" id="articleActionType" name="articleActionType" value="addArticle"/>
                                                    <input type="hidden" id="geography_id" name="geography_id" value=""/>
                                                    <br>
                                                    Category : <span id="categoryAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please select article category.</span><br>
                                                    <select id="categoryId" name="categoryId" style="width:512px;">
                                                        <option value="">Select category</option>
        <?php
        foreach ($category as $k => $rs) {
            ?>
                                                            <option value="<?php echo $rs['id']; ?>"><?php echo $rs['name']; ?></option>
                                                        <?php } ?>
                                                    </select>
                                                    <br>

                                                    Image : <div style="width: 250px;">
                                                        <input type="hidden" id="image" name="image"/>
                                                        <img id="imgDisplay" src="/uploads/noimage.jpg" width="100"/>
                                                        <input type="button" onclick="javascript: addPhotos('image');" style="float: right" value="Select image"/>
                                                    </div>
                                                    <br>
                                                    Short description : <span id="shortDescriptionAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please input some short descriptions.</span><br>
                                                    <div style="margin-bottom:10px">
                                                        <textarea id="short_description" name="short_description" rows="2" cols="20"></textarea>
                                                    </div>
                                                    Description : <span id="descriptionAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please input some descriptions.</span><br>
                                                    <div id="toGetHeight">
                                                        <textarea id="description" name="description" rows="4" cols="40" style="width:631px"></textarea>
                                                    </div>
                                                    <br>
                                                    Front page: &nbsp;&nbsp;
                                                    <input type="radio" name="front_page" value="yes" /> Yes &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="front_page" value="no" checked /> No<br><br>
                                                    Create Date: <br><input style="width: 200px" type="text" id="createDate" name="createDate" onclick="javascript: NewCssCal('createDate','yyyymmdd','arrow',true,24,false);"/><br><br>
                                                    Status : <br>
                                                    <select id="status" name="status" style="width:200px;">
                                                        <option value="yes">Yes</option>
                                                        <option value="pending">Pending</option>
                                                        <option value="no">No</option>
                                                        <option value="crawler">Crawler</option>
                                                    </select><br>
                                                    Allow post comment: &nbsp;&nbsp;
                                                    <input type="radio" name="comment" value="yes" /> Yes &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="comment" value="no" checked /> No<br><br>
                                                    Allow show comment: &nbsp;&nbsp;
                                                    <input type="radio" name="show_comment" value="yes" /> Yes &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="show_comment" value="no" checked /> No<br><br>
                                                    Attach multi files: <br>
                                                    <input type="file" class="multi" maxlength="10" name="attachs[]"/>
                                                    <div id="imageList"></div>


                                                </td>
                                                <td valign="top" width="245px">
                                                    <input type="button" value="Generate tags" onclick="javascript: genTags();"/>&nbsp;&nbsp;
                                                    <input type="button" value="Clear tags" onclick="javascript: clearTags();"/><br>
                                                    <fieldset id="fsAddArticle">
                                                        <legend>Frequency</legend>
                                                        <select style="width:72px" name="frequency[1]" id="frequency1" gtbfieldid="6">
                                                            <option value="-1">1 Word</option>
        <?php for ($i = 1; $i < 9; $i++) { ?>
                                                                <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
                                                            <?php } ?>

                                                        </select>
                                                        <select style="width:72px" name="frequency[2]" id="frequency2" gtbfieldid="7">
                                                            <option value="-1">2 Word</option>
        <?php for ($j = 1; $j < 9; $j++) { ?>
                                                                <option value="<?php echo $j; ?>"><?php echo $j; ?></option>
                                                            <?php } ?>

                                                        </select>
                                                        <select style="width:72px" name="frequency[3]" id="frequency3" gtbfieldid="8">
                                                            <option value="-1">3 Word</option>
        <?php for ($k = 1; $k < 9; $k++) { ?>
                                                                <option value="<?php echo $k; ?>"><?php echo $k; ?></option>
                                                            <?php } ?>                                                   
                                                        </select>
                                                        <select style="width:72px" name="frequency[4]" id="frequency4" gtbfieldid="9">
                                                            <option value="-1">4 Word</option>
        <?php for ($l = 1; $l < 9; $l++) { ?>
                                                                <option value="<?php echo $l; ?>"><?php echo $l; ?></option>
                                                            <?php } ?>

                                                        </select>
                                                        <select style="width:72px" name="frequency[5]" id="frequency5" gtbfieldid="10">
                                                            <option value="-1">5 Word</option>
        <?php for ($s = 1; $s < 9; $s++) { ?>
                                                                <option value="<?php echo $s; ?>"><?php echo $s; ?></option>
                                                            <?php } ?>
                                                        </select>
                                                        <select style="width:72px" name="frequency[6]" id="frequency6" gtbfieldid="11">
                                                            <option value="-1">6 Word</option>
        <?php for ($z = 1; $z < 9; $z++) { ?>
                                                                <option value="<?php echo $z; ?>"><?php echo $z; ?></option>
                                                            <?php } ?>
                                                        </select>
                                                    </fieldset>



                                                    <div style="height:20px">
                                                        <div id="keywordAlert" style="text-align: center;"></div>
                                                        <input type="hidden" name="removedTags" id="removedTags"/>
                                                    </div>
                                                    <hr style="margin-bottom:5px">
                                                    <div id="tagResult" style="width: 99%; height: 490px;overflow-x:hidden;overflow-y:scroll;"></div>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </fieldset>


                                <fieldset id="fsAddRelationBox">
                                    <legend>Relation box</legend>
                                    <div>
                                        <label for="categoryId">View type:</label>
                                        <input type="radio" name="view_type" value="article" checked="checked" /> Article &nbsp;&nbsp;
                                        <input type="radio" name="view_type" value="html"/>Html
                                    </div>
                                    <label>Box title:</label>
                                    <input style="width: 200px; border-color: green;" type="text" id="box_title" name="box_title"/>
                                    <br/>
                                    <label for="rbActive">Active:</label>
                                    <select id="rbActive"  name="rbActive" style="width:236px;">
                                        <option value="1">Yes</option>
                                        <option value="0">No</option>
                                    </select>
                                    <div id="divRelateBoxHtml" style="display: none">
                                        <div style="padding-left: 110px;">
                                            <textarea id="rbHtml" name="value_html" rows="4" cols="40" style="width:300px;"></textarea>
                                        </div>
                                    </div>
                                    <div id="divRelateBoxArticle">
                                        <label for="searchKeyword">Keyword : </label>
                                        <input style="width: 228px" type="text" id="rbKeyword"/>
                                        <input type="button" value="Search" id="rbSearchArticleSubmit"/>
                                        <br>
                                        <label for="date">Date : </label>
                                        <input style="width: 100px" type="text" id="dateFrom" name="dateFrom" onclick="javascript: NewCssCal('dateFrom','yyyymmdd','arrow')"/>
                                        To
                                        <input style="width: 100px" type="text" id="dateTo" name="dateTo" onclick="javascript: NewCssCal('dateTo','yyyymmdd','arrow')"/>
                                        <br>
                                        <label for="categoryId">Category : </label>
                                        <select id="rbCategoryId" style="width:236px;">
                                            <option value="">Select category</option>
        <?php
        foreach ($category as $k => $rs) {
            echo '<option value="' . $rs['id'] . '">' . $rs['name'] . '</option>';
        }
        ?>
                                        </select>
                                        <br>
                                        <div>
                                            <div style="float: left">
                                                <label for="categoryId">&nbsp;</label>
                                                <select id="rbSearchArticleResult" style="width:300px;height: 200px;" multiple></select>
                                            </div>
                                            <div style="float: left">
                                                <input type="button" value="    Select    " id="rbSelectArticle" style="margin: 70px 5px 0 10px;"/><br/>
                                                <input type="button" value="    Remove    " id="rbRemoveArticle" style="margin: 10px 5px 0 5px;"/>
                                            </div>
                                            <div style="float: left">
                                                <select id="rbSearchArticleSelect" name="articleSelect[]" style="width:300px;height: 200px;border-color: green;" multiple></select>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>

                                <div align="center">
                                    <input type="button" value="Create article" name="addArticleSubmit" id="addArticleSubmit" onclick="javascript: submitFormAddEditArticle('add');"/>

                                    <input type="reset" id="AddArticleReset"/>
                                </div><br>
                            </form>
                        </div>
        <?php
    } else {//edit article
        $rsEdit = $article->editArticle($_GET['id']);
        $rsEditAttach = $article->getArticleAttachs($_GET['id']);
        ?>
                        <script type="text/javascript" src="/admin/themes/default/js/nicEdit.js"></script>
                        <div id="formEditArticle">
                            <form method="post" action="/<?php echo $config ['admin_section']; ?>/article/<?php echo $_SESSION['articlePageEdit']; ?>" id="form" name="formEditArticle" enctype="multipart/form-data" style="padding-top: 10px">
                                <fieldset id="fsEditArticle">
                                    <legend>Edit article</legend>
                                    <table border="0" width="99%">
                                        <tbody>
                                            <tr>
                                                <td valign="top">
                                                    Title : <span id="titleAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please insert article title.</span><br>
                                                    <textarea id="title" name="title" rows="1" cols="10" style="width: 504px; height:16px; background:none;"><?php echo $rsEdit['rsArticle']['title']; ?></textarea>
                                                    <input type="hidden" id="articleActionType" name="articleActionType" value="updateArticle"/>
                                                    <input type="hidden" name="id" value="<?php echo $rsEdit['rsArticle']['id']; ?>"/>
                                                    <br>
                                                    Category : <span id="categoryAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please select article category.</span><br>
                                                    <select id="categoryId" name="categoryId" style="width:400px;">
                                                        <option value="">Select category</option>
        <?php
        $category = $article->get_cat_tree(0);
        foreach ($category as $k => $rs) {

            if ($rs['id'] == $rsEdit['rsArticle']['cat_id']) {
                ?>
                                                                <option value="<?php echo $rs['id']; ?>" selected><?php echo $rs['name']; ?></option>
                                                                <?php
                                                            } else {
                                                                ?>
                                                                <option value="<?php echo $rs['id']; ?>"><?php echo $rs['name']; ?></option>
                                                                <?php
                                                            }
                                                        }
                                                        ?>
                                                    </select>
                                                    <br>
                                                    Image : <div style="width: 250px;">
                                                        <input type="hidden" id="image" name="image" value="<?php echo $rsEdit['rsArticle']['image']; ?>"/>
                                                        <img id="imgDisplay" src="<?php echo $rsEdit['rsArticle']['image']; ?>" width="100"/>
                                                        <input type="button" onclick="javascript: addPhotos('image');" style="float: right" value="Select image"/>
                                                    </div>
                                                    <br>
                                                    Short description : <span id="shortDescriptionAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please input some short descriptions.</span><br>
                                                    <div style="margin-bottom:10px">
                                                        <textarea id="short_description" name="short_description" rows="2" cols="20"><?php echo $rsEdit['rsArticle']['short_description']; ?></textarea>
                                                    </div>
                                                    Description : <span id="descriptionAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please input some descriptions.</span><br>
                                                    <div id="toGetHeight">
                                                        <textarea id="description" name="description" rows="4" cols="40" style="width:631px"><?php echo $rsEdit['rsArticle']['description']; ?></textarea>
                                                    </div>
                                                    <br>
        <?php
        if ($rsEdit['rsArticle']['front_page'] == 'yes') {
            $front_pageYes = 'checked';
            $front_pageNo = '';
        } elseif ($rsEdit['rsArticle']['front_page'] == 'no') {
            $front_pageYes = '';
            $front_pageNo = 'checked';
        }
        ?>
                                                    Front page: &nbsp;&nbsp;
                                                    <input type="radio" name="front_page" value="yes" <?php echo $front_pageYes; ?> /> Yes &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="front_page" value="no" <?php echo $front_pageNo; ?> /> No<br><br>
                                                    Create Date: <br><input style="width: 200px" type="text" id="createDate" name="createDate" value="<?php echo $rsEdit['rsArticle']['create_date']; ?>" onclick="javascript: NewCssCal('createDate','yyyymmdd','arrow',true,24,false);"/><br><br>
                                                    Status : <br>
                                                    <select id="status" name="status" style="width:200px;">
        <?php
        if ($rsEdit['rsArticle']['status'] == 'yes') {
            echo '<option selected="selected" value="yes">Yes</option>';
            echo '<option value="pending">Pending</option>';
            echo '<option value="no">No</option>';
            echo '<option value="crawler">Crawler</option>';
        } else {
            if ($rsEdit['rsArticle']['status'] == 'pending') {
                echo '<option value="yes">Yes</option>';
                echo '<option selected="selected" value="pending">Pending</option>';
                echo '<option value="no">No</option>';
                echo '<option value="crawler">Crawler</option>';
            } else {
                if ($rsEdit['rsArticle']['status'] == 'crawler') {
                    echo '<option value="yes">Yes</option>';
                    echo '<option value="pending">Pending</option>';
                    echo '<option value="no">No</option>';
                    echo '<option selected="selected" value="crawler">Crawler</option>';
                } else {
                    echo '<option value="yes">Yes</option>';
                    echo '<option value="pending">Pending</option>';
                    echo '<option selected="selected" value="no">No</option>';
                    echo '<option value="crawler">Crawler</option>';
                }
            }
        }
        ?>
                                                    </select><br>
                                                        <?php
                                                        if ($rsEdit['rsArticle']['comment'] == 'yes') {
                                                            $commentYes = 'checked';
                                                            $commentNo = '';
                                                        } elseif ($rsEdit['rsArticle']['comment'] == 'no') {
                                                            $commentYes = '';
                                                            $commentNo = 'checked';
                                                        }
                                                        if ($rsEdit['rsArticle']['show_comment'] == 'yes') {
                                                            $showCommentYes = 'checked';
                                                            $showCommentNo = '';
                                                        } elseif ($rsEdit['rsArticle']['show_comment'] == 'no') {
                                                            $showCommentYes = '';
                                                            $showCommentNo = 'checked';
                                                        }
                                                        ?>
                                                    Allow post comment: &nbsp;&nbsp;
                                                    <input type="radio" name="comment" value="yes" <?php echo $commentYes; ?> /> Yes &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="comment" value="no" <?php echo $commentNo; ?> /> No<br><br>
                                                    Allow show comment: &nbsp;&nbsp;
                                                    <input type="radio" name="show_comment" value="yes" <?php echo $showCommentYes; ?> /> Yes &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="show_comment" value="no" <?php echo $showCommentNo; ?> /> No<br><br>
                                                    Attach multi files: <br>
                                                    <input type="file" class="multi" maxlength="10" name="attachs[]"/>
                                                    <div id="hiddenAttachDiv" style="display:none"></div>
                                                    <div id="removeImageList">
        <?php
        while ($rs = $db->fetch_array($rsEditAttach)) {
            ?>
                                                            <div id="removeAttachDiv_<?php echo $rs['id']; ?>">
                                                                <a class="MultiFile-remove" href="#MultiFile1_wrap" onclick="removeAttachFile('<?php echo $rs['id']; ?>');">x</a>
                                                                <span class="MultiFile-title" title="File selected: <?php echo $rs['real_filename']; ?>"><?php echo $rs['real_filename']; ?></span>
                                                            </div>
                                                            <?php
                                                        }
                                                        ?>
                                                    </div>
                                                    <div id="imageList"></div>


                                                </td>
                                                <td valign="top" width="245px">
                                                    <b>Tags:</b> <input type="button" onclick="addFileUpload()" value="Add more tag"/><br>
                                                    <script language="javascript" type="text/javascript">
                                                        function createRandomNumber(varLength) {
                                                            var sourceArr = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
                                                            var randomKey;
                                                            var randomCode = "qvsinh_";
                                                            for (i=0; i<varLength; i++) {
                                                                randomKey = Math.floor(Math.random()*sourceArr.length);
                                                                randomCode = randomCode + sourceArr[randomKey];
                                                            }
                                                            return randomCode;
                                                        }

                            
                                                        function addFileUpload(){
                                                            var liId = createRandomNumber(8);
                                                            var htmlTag = '<div id="k'+liId+'"><input id="key'+liId+'" type="text" size="25" value="" name="keyword[]" class="textbox"/><span class="keyword_remove" onclick="keyword_remove(\''+liId+'\');">Re</span><span class="keyword_spam" onclick="keyword_spam(\''+liId+'\');">Sp</span></div>';
                                                            $("#tagResult").append(htmlTag);
                                                        }


                          
                                                    </script>
                                                    <div id="tagResult" style="width: 99%; height: auto;overflow-x:hidden;overflow-y:scroll;">
        <?php
        $html = '';
        $i = 1;
        while ($rs = $db->fetch_array($rsEdit['rsTags'])) {
            $html.='<div id="k' . $i . '"><input id="key' . $i . '" type="text" size="25" value="' . $rs['tags'] . '" name="keyword[]" class="textbox"/>';
            $html.='<span class="keyword_remove" onclick="keyword_remove(' . $i . ');">Re</span> ';
            $html.='<span class="keyword_spam" onclick="keyword_spam(' . $i . ');">Sp</span></div>';
            $i++;
        }
        $html.='<div id="k' . $i . '"><input id="key' . $i . '" type="text" size="25" value="" name="keyword[]" class="textbox"/>';
        $html.='<span class="keyword_remove" onclick="keyword_remove(' . $i . ');">Re</span> ';
        $html.='<span class="keyword_spam" onclick="keyword_spam(' . $i . ');">Sp</span></div>';
        $i = $i + 1;
        $html.='<div id="k' . $i . '"><input id="key' . $i . '" type="text" size="25" value="" name="keyword[]" class="textbox"/>';
        $html.='<span class="keyword_remove" onclick="keyword_remove(' . $i . ');">Re</span> ';
        $html.='<span class="keyword_spam" onclick="keyword_spam(' . $i . ');">Sp</span></div>';
        $i = $i + 1;
        $html.='<div id="k' . $i . '"><input id="key' . $i . '" type="text" size="25" value="" name="keyword[]" class="textbox"/>';
        $html.='<span class="keyword_remove" onclick="keyword_remove(' . $i . ');">Re</span> ';
        $html.='<span class="keyword_spam" onclick="keyword_spam(' . $i . ');">Sp</span></div>';
        $i = $i + 1;
        $html.='<div id="k' . $i . '"><input id="key' . $i . '" type="text" size="25" value="" name="keyword[]" class="textbox"/>';
        $html.='<span class="keyword_remove" onclick="keyword_remove(' . $i . ');">Re</span> ';
        $html.='<span class="keyword_spam" onclick="keyword_spam(' . $i . ');">Sp</span></div>';
        echo $html;
        ?>
                                                        <input type="hidden" name="removedTags" id="removedTags"/>
                                                    </div>

                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </fieldset>

                                <fieldset id="fsEditRelationBox">
                                    <legend>Relation box</legend>
                                    <div>
                                        <label for="categoryId">View type:</label>
                                        <input type="radio" name="view_type" value="article" <?php if ($rsEdit['rsRelateBox']['view_type'] != 'html')
                                                    echo 'checked="checked"'; ?> /> Article &nbsp;&nbsp;
                                        <input type="radio" name="view_type" <?php if ($rsEdit['rsRelateBox']['view_type'] == 'html')
                                                    echo 'checked="checked"'; ?> value="html"/>Html
                                    </div>
                                    <label>Box title:</label>
                                    <input style="width: 200px; border-color: green;" type="text" id="box_title" name="box_title" value="<?php echo $rsEdit['rsRelateBox']['box_title']; ?>"/>
                                    <input type="hidden" id="rbId" name="rbId" value="<?php echo $rsEdit['rsRelateBox']['id']; ?>"/>
                                    <br/>
                                    <label>Active:</label>
                                    <select id="rbActive" name="rbActive" style="width:236px;">
                                        <option <?php echo $rsEdit['rsRelateBox']['active'] == 1 ? 'selected="selected"' : ''; ?> value="1">Yes</option>
                                        <option <?php echo isset($rsEdit['rsRelateBox']['active']) && $rsEdit['rsRelateBox']['active'] == 0 ? 'selected="selected"' : ''; ?> value="0">No</option>
                                    </select>
                                    <div id="divRelateBoxHtml" style="display: none">
                                        <div style="padding-left: 110px;">
                                            <textarea id="rbHtml" name="value_html" rows="4" cols="40" style="width:300px;"><?php if ($rsEdit['rsRelateBox']['view_type'] == 'html')
                                                    echo $rsEdit['rsRelateBox']['value']; ?></textarea>
                                        </div>
                                    </div>
                                    <div id="divRelateBoxArticle">
                                        <label for="searchKeyword">Keyword : </label>
                                        <input style="width: 228px" type="text" id="rbKeyword"/>
                                        <input type="button" value="Search" id="rbSearchArticleSubmit"/>
                                        <br>
                                        <label for="date">Date : </label>
                                        <input style="width: 100px" type="text" id="dateFrom" name="dateFrom" onclick="javascript: NewCssCal('dateFrom','yyyymmdd','arrow')"/>
                                        To
                                        <input style="width: 100px" type="text" id="dateTo" name="dateTo" onclick="javascript: NewCssCal('dateTo','yyyymmdd','arrow')"/>
                                        <br>
                                        <label for="categoryId">Category : </label>
                                        <select id="rbCategoryId" style="width:236px;">
                                            <option value="">Select category</option>
        <?php
        foreach ($category as $k => $rs) {
            echo '<option value="' . $rs['id'] . '">' . $rs['name'] . '</option>';
        }
        ?>
                                        </select>
                                        <br>
                                        <div>
                                            <div style="float: left">
                                                <label for="categoryId">&nbsp;</label>
                                                <select id="rbSearchArticleResult" style="width:300px;height: 200px;" multiple></select>
                                            </div>
                                            <div style="float: left">
                                                <input type="button" value="    Select    " id="rbSelectArticle" style="margin: 70px 5px 0 10px;"/><br/>
                                                <input type="button" value="    Remove    " id="rbRemoveArticle" style="margin: 10px 5px 0 5px;"/>
                                            </div>
                                            <div style="float: left">
                                                <select id="rbSearchArticleSelect" name="articleSelect[]" style="width:300px;height: 200px;border-color: green;" multiple>
        <?php if (isset($rsEdit['rsRelateBox']['articleValue']))
            echo $rsEdit['rsRelateBox']['articleValue']; ?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                                <div align="center">
                                    <input type="button" value="Update article" name="editArticleSubmit" id="editArticleSubmit" onclick="javascript: submitFormAddEditArticle('edit');"/>
                                </div><br>
                            </form>
                        </div>

                        <?php
                    }
                    ?>
                </div>
                <div style="height:10px"></div>
            </div>
            <?php
        }else {
            
            ?>

            <div id="rightnow">
                <h3 class="reallynow">
                    <span>Search</span>
                    <br />
                </h3>
                <div class="youhave">
                    <form method="get" action="/<?php echo $config ['admin_section']; ?>/article" id="form" name="form" enctype="multipart/form-data" style="padding-top: 10px">

                        <label for="searchKeyword">Keyword : </label>
                        <input style="width: 200px" type="text" id="searchKeyword" name="searchKeyword" value="<?php echo htmlentities($_GET['searchKeyword'], ENT_QUOTES, "UTF-8"); ?>"/>
                        <input type="hidden" id="articleActionType" name="articleActionType" value="searchArticle"/>
                        <br>
                        <label for="date">Date : </label>
                        <input style="width: 200px" type="text" id="dateFrom" name="dateFrom" value="<?php echo $_GET['dateFrom']; ?>" onclick="javascript: NewCssCal('dateFrom','yyyymmdd','arrow')"/>
                        To
                        <input style="width: 200px" type="text" id="dateTo" name="dateTo" value="<?php echo $_GET['dateTo']; ?>" onclick="javascript: NewCssCal('dateTo','yyyymmdd','arrow')"/>
                        <br>
                        <label for="categoryId">Category : </label>
                        <select id="categoryId" name="categoryId" style="width:208px;">
                            <option value="">Select category</option>
                            <?php
                            $category = $article->get_cat_tree(0);
                            foreach ($category as $k => $rs) {
                                if ($_GET['categoryId'] == $rs['id']) {
                                    echo '<option selected value="' . $rs['id'] . '">' . $rs['name'] . '</option>';
                                } else {
                                    echo '<option value="' . $rs['id'] . '">' . $rs['name'] . '</option>';
                                }
                            }
                            ?>
                        </select>
                        <br>

                        <div align="center">
                            <input type="submit" value="Search" name="searchArticleSubmit" id="searchArticleSubmit"/>
                        </div>
                    </form>
                </div>
            </div><br>

            <div id="rightnow">
                <form method="post" action="" id="formStatusView">
                    <h3 class="reallynow">
                        <span>Articles</span>
                        <span style="float: right;">

                            <select name="status" style="width:150px; padding:0px;" onchange="javascript: statusFilter();">
                                <?php
                                if (isset($_POST['status'])) {
                                    $_SESSION['articleStatusFilter'] = $_POST['status'];
                                }
                                if ($_SESSION['articleStatusFilter'] == 'yes') {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option selected="selected" value="yes">Yes only</option>
                                            <option value="pending">Pending only</option>
                                            <option value="no">No only</option>
                                            <option value="crawler">Crawler only</option>';
                                } elseif ($_SESSION['articleStatusFilter'] == 'pending') {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option value="yes">Yes only</option>
                                            <option selected="selected" value="pending">Pending only</option>
                                            <option value="no">No only</option>
                                            <option value="crawler">Crawler only</option>';
                                } elseif ($_SESSION['articleStatusFilter'] == 'no') {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option value="yes">Yes only</option>
                                            <option value="pending">Pending only</option>
                                            <option selected="selected" value="no">No only</option>
                                            <option value="crawler">Crawler only</option>';
                                } elseif ($_SESSION['articleStatusFilter'] == 'crawler') {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option value="yes">Yes only</option>
                                            <option value="pending">Pending only</option>
                                            <option value="no">No only</option>
                                            <option selected="selected" value="crawler">Crawler only</option>';
                                } else {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option value="yes">Yes only</option>
                                            <option value="pending">Pending only</option>
                                            <option value="no">No only</option>
                                            <option value="crawler">Crawler only</option>';
                                }
                                ?>
                            </select>
                            <input type="hidden" id="articleActionType" name="articleActionType" value="statusFilter"/>
                            <a class="add" href="javascript: addPhotos('');">Add images</a> <a class="add" href="javascript: viewAddArticle();">Add article</a>

                        </span>
                        <br />
                    </h3>
                </form>
                <div class="youhave">
                    <form method="post" action="" id="formView">
                        <div id="rsMessages" style="text-align: center;"><?php if (isset($_SESSION['rsMessages'])) {
                                echo $_SESSION['rsMessages'];
                                $_SESSION['rsMessages'] = '';
                            } ?></div>
                        <table width="100%">
                            <tbody>
                                <tr height="35px">
                                    <td width="40px">&nbsp;</td>
                                    <td><b>Title</b></td>
                                    <td style="text-align: center"><b title="Thumb up">TU</b></td>
                                    <td style="text-align: center"><b title="View count">VC</b></td>
                                    <td width="110px" style="text-align: center"><b>Date</b></td>
                                    <td width="120px" style="text-align: center"><b>Category</b></td>
                                    <td width="40px" style="text-align: center"><b>Status</b></td>
                                    <td width="80px" style="text-align: center"><b>Action</b></td>
                                </tr>
                                <?php
                                if (isset($_POST['status']) AND $_POST['status'] != '') {
                                    $status = " WHERE a.status='" . filter($_POST['status']) . "' ";
                                    $rsAllArticle = $article->getAllArticle($config ['total_article_on_admin'], $status);
                                } else {
                                    $rsAllArticle = $article->getAllArticle($config ['total_article_on_admin']);
                                }
                                $i = 0;
                                while ($rs = $db->fetch_array($rsAllArticle['rs'])) {
                                    $i++;
                                    if ($rs['front_page'] == 'yes') {
                                        $frontPageImg = 'circle-green.png';
                                        $frontPageTitle = 'Hot news actived!';
                                    } else {
                                        $frontPageImg = 'circle-red.png';
                                        $frontPageTitle = 'Not show in Hot news!';
                                    }
                                    ?>
                                    <tr class="listItem">
                                        <td class="a-center"><?php if ($rs['user_id'] == 8) {
                                        echo '<span style="color: #ff0000">';
                                    } else {
                                        echo '<span>';
                                    } echo $i . '</span>'; ?></td>
                                        <td>&nbsp;&nbsp;<a href="/<?php echo $config ['admin_section']; ?>/detail?id=<?php echo $rs['id']; ?>&keepThis=true&TB_iframe=true&height=600&width=500" title="<?php echo $rs['title']; ?>" class="thickbox"><?php echo stripslashes($rs['title']); ?></a></td>
                                        <td style="text-align: center">
        <?php echo $rs['thumb_up']; ?>
                                        </td>
                                        <td style="text-align: center">
        <?php echo $rs['view_count']; ?>
                                        </td>
                                        <td align="center" style="font-size:10px;"><?= $rs['create_date'] ?></td>

                                        <td>&nbsp;&nbsp;<a href="/<?php echo $config ['admin_section']; ?>/article&articleActionType=searchArticle&categoryId=<?php echo $rs['cat_id']; ?>&searchArticleSubmit=Search"><?php echo $rs['category_name']; ?></a></td>
                                        <td style="text-align: center"><?php echo ucfirst($rs['status']); ?></td>
                                        <td valign="middle"><input type="checkbox" id="multiArticleId[]" name="multiArticleId[]" value="<?php echo $rs['id']; ?>">
                                            <a href="javascript: void(0);"><img onclick="javascript: frontPage('<?php echo $rs['id']; ?>',this);" height="16" width="16" title="<?php echo $frontPageTitle; ?>" src="<?php echo $config ['admin_images_url']; ?>/icons/<?php echo $frontPageImg; ?>"/></a>
                                            <a href="javascript: editArticle('<?php echo $rs['id']; ?>');"><img height="16" width="16" title="Edit article" src="<?php echo $config ['admin_images_url']; ?>/icons/page_white_edit.png"/></a>
                                            <a href="javascript: deleteArticle(<?php echo $rs['id']; ?>,'<?php echo $rs['title']; ?>');"><img height="16" width="16" title="Delete article" src="<?php echo $config ['admin_images_url']; ?>/icons/page_white_delete.png"/></a>
                                        </td>
                                    </tr>
    <?php } ?>
                            </tbody>
                        </table>
                        <div style="text-align: right">
                            <b>With selected items:</b>
                            <select id="action" name="action" onchange="javascript: actionMultil(this.value);" style="width:120px; padding:0px;">
                                <option value="">Select action</option>
                                <option value="yes">Set status to yes</option>
                                <option value="pending">Set status to pending</option>
                                <option value="no">Set status to no</option>
                                <option value="delete">Delete</option>
                            </select>&nbsp;&nbsp;&nbsp;
                            <b>Select all/Unselect all:</b>
                            <input type="checkbox" name="checkall" onclick="javascript: checkedAll('formView');">
                            <input type="hidden" id="articleActionType" name="articleActionType" value="actionMultil"/>
                        </div>
                    </form>
                </div>
                <div class="linepagination">
                    <div class="pagination">
                        <ul>
    <?php
    $totalRows = $rsAllArticle['totalRows'];
    $totalPages = ceil($totalRows / $config ['total_article_on_admin']);
    echo pagingAdmin($config ['page'], $totalPages, '', '');
    ?>
                        </ul>
                    </div>

                </div>
            </div>

    <?php
}
?>
    </div>
</div>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/footer.php'; ?>
